﻿/******************************************************************************
    myBoard is a port of MacOS X dashboard application for windows.
    Copyright (C) 2007,2008  by Yann ALET
    Email : yann.alet@gmail.com

    myBoard is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    myBoard is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
****************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using Guide.XMLTV;
using myBoard.Framework;
using System.ComponentModel;

namespace Guide.XMLTV
{
    public enum GrabbersEnum
    {
        tv_grab_uk_rt,tv_grab_na_dd,tv_grab_de_tvtoday,tv_grab_fi,tv_grab_it,tv_grab_es,tv_grab_nl,tv_grab_dk,tv_grab_huro,
        tv_grab_jp, tv_grab_se_swedb, tv_grab_fr, tv_grab_no, tv_grab_pt, tv_grab_be, tv_grab_br, tv_grab_ch_search, tv_grab_ee,
            tv_grab_il,tv_grab_is,tv_grab_re,tv_grab_ar
    }

    public class Grabbers : Dictionary<GrabbersEnum, Grabber> , INotifyPropertyChanged
    {
        // Fields
        private GrabbersEnum _activeGrabber;

        // Events
        public event PropertyChangedEventHandler PropertyChanged;

        // Methods
        public Grabbers()
        {
            base.Add(GrabbersEnum.tv_grab_fr, new Grabber(GrabbersEnum.tv_grab_fr));
            base.Add(GrabbersEnum.tv_grab_uk_rt, new Grabber(GrabbersEnum.tv_grab_uk_rt));
            base.Add(GrabbersEnum.tv_grab_ar, new Grabber(GrabbersEnum.tv_grab_ar));
            base.Add(GrabbersEnum.tv_grab_be, new Grabber(GrabbersEnum.tv_grab_be));
            base.Add(GrabbersEnum.tv_grab_ch_search, new Grabber(GrabbersEnum.tv_grab_ch_search));
            base.Add(GrabbersEnum.tv_grab_it, new Grabber(GrabbersEnum.tv_grab_it));
            base.Add(GrabbersEnum.tv_grab_es, new Grabber(GrabbersEnum.tv_grab_es));
            this.SetActiveGrabber(GrabbersEnum.tv_grab_uk_rt);
        }

        public void SetActiveGrabber(GrabbersEnum grabber)
        {
            this._activeGrabber = grabber;
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs("ActiveGrabber"));
            }
        }

        // Properties
        public Grabber ActiveGrabber
        {
            get
            {
                return base[this._activeGrabber];
            }
            set
            {
                foreach (KeyValuePair<GrabbersEnum, Grabber> pair in this)
                {
                    if (pair.Value == value)
                    {
                        this._activeGrabber = pair.Key;
                        pair.Value.UpdateChannelsSelection();
                        if (this.PropertyChanged != null)
                        {
                            this.PropertyChanged(this, new PropertyChangedEventArgs("ActiveGrabber"));
                        }
                        break;
                    }
                }
            }
        }

    }
}
